package com.enzo.pcms.common.util;

import java.util.Locale;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextUtil implements ApplicationContextAware {
	private static ApplicationContext context = null;
	private static ApplicationContextUtil util = null;

	public synchronized static ApplicationContextUtil init() {
		if (util == null) {
			util = new ApplicationContextUtil();
		}
		return util;
	}

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		context = applicationContext;
	}

	public synchronized static Object getBean(String beanName) {
		return context.getBean(beanName);
	}
	public synchronized static ApplicationContext getContext() {
		return context;
	}
	
	public static String getValue(String key){
		return context.getMessage(key, null, Locale.getDefault());
	}
	
	public static String getValue(String key,Object[] objs,Locale locale){
		return context.getMessage(key, objs,locale);
	}
}
